load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc_test", "rust_library", "rust_test")

DEPENDENCIES = [
    # Keep sorted.
    "//packages/ic-error-types",
    "//rs/artifact_pool",
    "//rs/canister_sandbox:backend_lib",
    "//rs/config",
    "//rs/consensus",
    "//rs/consensus/certification",
    "//rs/consensus/cup_utils",
    "//rs/consensus/dkg",
    "//rs/consensus/utils",
    "//rs/crypto",
    "//rs/crypto/for_verification_only",
    "//rs/cycles_account_manager",
    "//rs/execution_environment",
    "//rs/interfaces",
    "//rs/interfaces/registry",
    "//rs/interfaces/state_manager",
    "//rs/ledger_suite/icp:icp_ledger",
    "//rs/messaging",
    "//rs/monitoring/logger",
    "//rs/monitoring/metrics",
    "//rs/nervous_system/common",
    "//rs/nns/common",
    "//rs/nns/constants",
    "//rs/nns/governance/api",
    "//rs/protobuf",
    "//rs/registry/canister/api",
    "//rs/registry/client",
    "//rs/registry/helpers",
    "//rs/registry/keys",
    "//rs/registry/local_store",
    "//rs/registry/nns_data_provider",
    "//rs/registry/subnet_type",
    "//rs/registry/transport",
    "//rs/replicated_state",
    "//rs/state_manager",
    "//rs/types/types",
    "@crate_index//:candid",
    "@crate_index//:clap",
    "@crate_index//:hex",
    "@crate_index//:ic-agent",
    "@crate_index//:mockall",
    "@crate_index//:prost",
    "@crate_index//:rand",
    "@crate_index//:rayon",
    "@crate_index//:serde",
    "@crate_index//:serde_json",
    "@crate_index//:slog",
    "@crate_index//:slog-async",
    "@crate_index//:tempfile",
    "@crate_index//:time",
    "@crate_index//:tokio",
    "@crate_index//:tower",
    "@crate_index//:url",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//packages/pocket-ic",
    "//rs/crypto/sha2",
    "//rs/interfaces/state_manager/mocks",
    "//rs/nervous_system/agent",
    "//rs/nervous_system/chunks",
    "//rs/nervous_system/integration_tests:nervous_system_integration_tests",
    "//rs/nns/test_utils",
    "//rs/test_utilities/consensus",
    "//rs/test_utilities/types",
    "@crate_index//:pretty_assertions",
    "@crate_index//:strum",
]

MACRO_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:async-trait",
]

ALIASES = {}

rust_library(
    name = "replay",
    srcs = glob(["src/**"]),
    aliases = ALIASES,
    crate_name = "ic_replay",
    proc_macro_deps = MACRO_DEPENDENCIES,
    version = "0.9.0",
    visibility = [
        "//rs:system-tests-pkg",
        "//rs:tools-pkg",
    ],
    deps = DEPENDENCIES,
)

rust_binary(
    name = "ic-replay",
    srcs = ["src/main.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    visibility = [
        "//rs:release-pkg",
        "//rs:system-tests-pkg",
    ],
    deps = DEPENDENCIES + [":replay"],
)

rust_doc_test(
    name = "replay_doc_test",
    crate = ":replay",
)

rust_test(
    name = "replay_test",
    crate = ":replay",
    deps = DEPENDENCIES + DEV_DEPENDENCIES,
)

DEV_DATA = [
    # Keep sorted.
    "//rs/pocket_ic_server:pocket-ic-server",
    "//rs/registry/canister:registry-canister-test",
]

DEV_ENV = {
    # Keep sorted.
    "REGISTRY_CANISTER_TEST_WASM_PATH": "$(rootpath //rs/registry/canister:registry-canister-test)",
    "POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
}

rust_test(
    name = "player_integration_tests",
    srcs = ["tests/player.rs"],
    data = DEV_DATA,
    env = DEV_ENV,
    proc_macro_deps = MACRO_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES + [":replay"],
)
